package com.vunguyen.dao;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.vunguyen.model.Canbo;
import com.vunguyen.model.Congvan;
import com.vunguyen.model.Congvanden;
import com.vunguyen.model.Giangvien;
import com.vunguyen.model.Phieubaobu;
import com.vunguyen.model.Phieubaonghi;
import com.vunguyen.model.Phieudangky;
import com.vunguyen.model.Phieudoigiangvien;
import com.vunguyen.model.Phieudoiphong;

@Repository
public class PhieuDangKyDAOImpl implements PhieuDangKyDAO {
	@Autowired
	private SessionFactory sessionFactory;

	@SuppressWarnings("unchecked")
	@Override
	public List<Phieudangky> getListPhieuDangKy() {
		return sessionFactory.getCurrentSession().createQuery("From Phieudangky").list();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Phieubaobu> getListPhieubaobu() {
		return sessionFactory.getCurrentSession().createQuery("From Phieubaobu").list();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Phieubaonghi> getListPhieubaonghi() {
		return sessionFactory.getCurrentSession().createQuery("From Phieubaonghi").list();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Phieudoiphong> getListPhieudoiphong() {
		return sessionFactory.getCurrentSession().createQuery("From Phieudoiphong").list();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Phieudoigiangvien> getListPhieudoigiangvien() {
		return sessionFactory.getCurrentSession().createQuery("From Phieudoigiangvien").list();
	}

	@Override
	public void themPhieuDangKy(Phieudangky phieudangky) {
		Session session = this.sessionFactory.getCurrentSession();
		session.save(phieudangky);
	}

	@Override
	public void themPhieubaonghi(Phieubaonghi phieubaonghi) {
		Session session = this.sessionFactory.getCurrentSession();
		session.save(phieubaonghi);
		
	}

	@Override
	public void themPhieubaobu(Phieubaobu phieubaobu) {
		try{
		Session session = this.sessionFactory.getCurrentSession();
		session.save(phieubaobu);
		}
		catch(Exception e)
		{
			
		}
		
	}

	@Override
	public void themPhieudoiphong(Phieudoiphong phieudoiphong) {
		Session session = this.sessionFactory.getCurrentSession();
		session.save(phieudoiphong);
		
	}

	@Override
	public void themPhieudoigiangvien(Phieudoigiangvien phieudoigiangvien) {
		Session session = this.sessionFactory.getCurrentSession();
		session.save(phieudoigiangvien);
		
	}

	@Override
	public void themGiangvien(Giangvien giangvien) {
		Session session = this.sessionFactory.getCurrentSession();
		session.save(giangvien);
		
	}

	@Override
	public Phieubaonghi getPhieubaonghiById(int idphieubaonghi) {
		return (Phieubaonghi) sessionFactory.getCurrentSession()
				.createQuery("FROM Phieubaonghi WHERE idPhieu='" + idphieubaonghi + "'")
				.list().get(0);
	}

	@Override
	public void xoaPhieudangky(int idphieu) {
		Session session = this.sessionFactory.getCurrentSession();
		Phieudangky phieudangky = (Phieudangky) session.load(Phieudangky.class, idphieu);
        if(phieudangky != null ){
            session.delete(phieudangky);
        }	
	}
	



}
